﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Baza.EF.DAL;

namespace Baza.EF.BLL
{
    public class DACustomers
    {

        public static List<ad_Customer_Get_Rate_By_ApartmanID_Result> GetRateByApartmanId(int apartmanID)
        {
            return Connection.dm.ad_Customer_Get_Rate_By_ApartmanID(apartmanID).ToList();
        }

        public static List<ad_Customer_Ge_Active_Apartman_By_ApartmanID_Result> getActiveApartman(int apartmanID, DateTime checkIn, DateTime checkOut)
        {
            return Connection.dm.ad_Customer_Ge_Active_Apartman_By_ApartmanID(apartmanID,checkIn,checkOut).ToList();
        }
        public static Apartments getApartmanByApartmanID(int apartmanID)
        {
            return Connection.dm.ad_Customer_GetApartman_By_ApartmanID(apartmanID).FirstOrDefault();
        }
        public static void activateCustomer(int id, string email)
        {
            Connection.dm.ad_Customer_ActivateAccount(id, email);
        }
        public static bool checkEmail( string email)
        {
            return Convert.ToBoolean(Connection.dm.ad_Customers_Check_Email(email).FirstOrDefault());
        }
       
        public static List<ad_Customer_Get_Apartmans_By_OwnerID_Result> getApartmasbyOwnerID(int ownerID)
        {
            return Connection.dm.ad_Customer_Get_Apartmans_By_OwnerID(ownerID).ToList();
        }
        public static ad_Customer_Get_Ownet_By_ApartmanID_Result getOwnerByApartmanID(int apartmanID)
        {
            return Connection.dm.ad_Customer_Get_Ownet_By_ApartmanID(apartmanID).FirstOrDefault();

        }
        public static string getApartmanTypeByApartmanID(int apartmanID)
        {
            return Connection.dm.ad_Customer_Get_TypeOfApartmen_By_ApartmanID(apartmanID).FirstOrDefault();
        }
        public static Customers getCustomerByID(int customerID )
        {
            return Connection.dm.ad_Customer_Get_By_ID(customerID).FirstOrDefault();
        }
        public static void Ocjeni( int ApartmanID , int Rate , int CustomerID) {

            Connection.dm.ad_Customer_Rates_Insert(CustomerID, ApartmanID, Rate);
        }
        public static Apartments getPicturesOfApartman(int ID )
        {
            return Connection.dm.Apartments.Where(x => x.ApartmentID == ID).Take(1).FirstOrDefault();
            
        }
        public static List<ad_Customer_Reservation_By_CustomerID_Result> getAllReservations(int CustomerID)
        {
            return Connection.dm.ad_Customer_Reservation_By_CustomerID(CustomerID).ToList();
        }
        public static bool AddNewReservation(int ApartmanID , int CustomerID , int UserID , DateTime CheckIn, DateTime CheckOut , decimal Price , int NumberGuest)
        {

            if (CheckAvailability(ApartmanID, CheckIn, CheckOut))
            {
                Connection.dm.ad_Customer_Reservation_Insert(ApartmanID, CustomerID, UserID, CheckIn, CheckOut, Price, NumberGuest);
                return true;
            }
            else
                return false;
        }
        public static bool CheckAvailability(int apartmanID , DateTime checkIn , DateTime checkOut)
        {
         return Convert.ToBoolean(Connection.dm.ad_Customer_Check_Period_BY_ApartmanID(apartmanID,checkIn,checkOut).FirstOrDefault());
        }
        public static List<ad_Customers_GetApartmans_Search_Result> getApartman( int start , int end)
        {
            return Connection.dm.ad_Customers_GetApartmans_Search(start,end).ToList();
        }
        public static List<ad_Customers_Apartman_SELECT_BY_CitYID_Result> getApartmansByCityID(int ID , int start , int max , DateTime startD , DateTime endD)
        {
            return Connection.dm.ad_Customers_Apartman_SELECT_BY_CitYID(ID,start,max,startD,endD).ToList();
        }
        public static int getCountApartman()
        {
           return Convert.ToInt32(Connection.dm.ad_Customers_Apartman_GetTotalCount().FirstOrDefault());
        }
        public static Apartments GetApartmanByID (int id)
        {
            return Connection.dm.ad_Customers_GetApartman_By_ID(id).FirstOrDefault();
        }
        public static Prices getPriceByApartmanID( int ApartmanID, DateTime start , DateTime end )
        {
          return  Connection.dm.ad_Customers_GetPeriodPrice_By_ApartmanID(ApartmanID,start,end).FirstOrDefault();
        }
        public static List<Cities> GetAllCities()
        {
            return Connection.dm.ad_Cities_Select().ToList();
        }
        public static List<Descriptions> GetDescriptions(int ID)    
        {
            return Connection.dm.ad_Customers_Apartman_Get_Description(ID).ToList();

        }

    }
}
